// Before using the script the composite images were split, then segmented using the provided WEKA .model files,then again put back to binary composite images with the following channels; Ch1 DAPI, Ch2 Iba1, Ch3 BrdU. 
// The results were transferred to Excel for sorting, before analysis in Graphpad.

name=getInfo("image.filename"); 

run("Colors...", "foreground=white background=black selection=yellow");

//Area-selection measurment 
run("Measure");
run("Clear Outside", "stack");
run("Select None"); 

run("Split Channels");

selectWindow("C1-"+name+"");
run("Analyze Particles...", "size=10-Infinity show=Masks display=Nothing slice");
run("Blue");
rename("DAPI-"+name+"");
selectWindow("C1-"+name+"");
close();

selectWindow("C2-"+name+"");
run("Analyze Particles...", "size=10-Infinity show=Masks stack");
run("Green");
rename("IBA1 including processes-"+name+"");
selectWindow("C2-"+name+"");
close();

selectWindow("C3-"+name+"");
run("Analyze Particles...", "size=10-Infinity show=Masks slice");
run("Red");
rename("BrdU-"+name+"");
selectWindow("C3-"+name+"");
close();
selectWindow("DAPI-"+name+"");
run("Create Selection");
roiManager("Add");
selectWindow("BrdU-"+name+"");
roiManager("Select", 0);
run("Clear Outside", "slice");
run("Select None");

selectWindow("IBA1 including processes-"+name+"");
run("Duplicate...", "duplicate");
rename("IBA1+DAPI+-"+name+""); 
roiManager("Select", 0);
run("Clear Outside", "slice");
roiManager("Delete");

selectWindow("BrdU-"+name+"");
run("Create Selection"); 
roiManager("Add"); 
selectWindow("IBA1 including processes-"+name+"");
run("Duplicate...", "duplicate");
rename("BrdU+IBA1+-"+name+"");
roiManager("Select", 0);
run("Clear Outside", "slice");
roiManager("Delete");

selectWindow("BrdU-"+name+"");
run("Select None");
setAutoThreshold("Default dark");
setOption("BlackBackground", true);
run("Convert to Mask");
run("Analyze Particles...", "size=1-Infinity show=Masks display slice");

selectWindow("IBA1 including processes-"+name+"");
run("Select None");
setAutoThreshold("Default dark");
setOption("BlackBackground", true);
run("Convert to Mask");
run("Analyze Particles...", "size=1-Infinity show=Masks display slice");

run("Duplicate...", "duplicate");
rename("IBA1 cells 95um-"+name+"");
setAutoThreshold("Default");
setOption("BlackBackground", true);
run("Convert to Mask");
run("Analyze Particles...", "size=95-600 show=Masks display slice");

selectWindow("DAPI-"+name+"");
run("Select None");
setAutoThreshold("Default dark");
setOption("BlackBackground", true);
run("Convert to Mask");
run("Analyze Particles...", "size=1-Infinity show=Masks display slice");
selectWindow("BrdU+IBA1+-"+name+"");
run("Select None");
run("Analyze Particles...", "size=10-Infinity circularity=0.3-1.00 show=Masks display");
selectWindow("IBA1+DAPI+-"+name+"");
run("Select None");
run("Analyze Particles...", "size=30-Infinity circularity=0.2-1.00 show=Masks display");

//To see the analysed images and steps, stop here. The images labeled "masks of..." represent the objects analysed in the results. 
run("Close All");

//Troubleshoot issues: Make sure the results show labels. As the script uses selection to mask over images make sure the "clear outside"-step in the script actually clears what is defined as outside the wanted selection - this has been issue when using the script between different computers. 
